<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE table PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
</head>
<body>
<table id="role_list_datagrid"  class="easyui-datagrid" data-options="url:'system/role/list.do',idField:'id',rownumbers:true,maximized:true,singleSelect:true,
toolbar : [{text:'添加', iconCls:'icon-add', handler:function(){openDialog('add');}}, 
			{text:'修改', iconCls:'icon-edit', handler:function(){openDialog('edit');}}, 
			{text:'删除', iconCls:'icon-cancel', handler:doDelete}]">
<thead>
	<tr>
		<th data-options="field:'name',width:150,align:'center'">角色名</th>
		<th data-options="field:'alias',width:180,align:'center'">别名</th>
		<th data-options="field:'id',width:180,align:'center',formatter:formatCell">权限</th>
	</tr>
</thead>
</table>
<script type="text/javascript">
	function formatCell(value) {
		return '<span class="icon-key" onclick="editPower('+value+')"></span>';
	}
	function editPower(id) {
		$('<div id="power_edit_dialog"></div>').dialog({
			title:"修改权限",
			width:400,
			height:500,
			cache:false,
			href:'system/role/editPower.do?id='+id,
			closed:false,
			modal: true,
			onClose:function() {
				$(this).dialog('destroy');
			}
		});
	} 
	function openDialog(type) {
		var title = '';
		var id = '';
		if(type=='add') {
			title = '添加菜单';
		}else if(type='edit') {
			title = '修改菜单';
			var row = $("#role_list_datagrid").datagrid('getSelected');
			if(row==null) {
				$.messager.alert('提示信息','请至少选择一行','warning');
				return;
			}
			id = row.id;
		}
		$('<div id="role_edit_dialog"></div>').dialog({
			title:title,
			width:500,
			height:140,
			cache:false,
			href:'system/role/edit.do?id='+id,
			closed:false,
			modal: true,
			buttons:[{
				text:'确定',
				handler:function(){
					doSubmit();
				}
			},{
				text:'取消',
				handler:function(){
					$("#role_edit_dialog").dialog('destroy');
			}}],
			onClose:function() {
				$(this).dialog('destroy');
			}
		});
	}
	function doDelete() {
		var row = $("#role_list_datagrid").datagrid('getSelected');
		var id = row.id;
		var msg = '是否删除"'+row.name+'"';
		$.messager.confirm('删除确认', msg, function(r){
			if(r) {
				$.ajax({
					type : 'POST',
					url : "system/role/delete.do?id="+id,
					success : function(data) {
						$.messager.show({
							title:'提示信息',
							msg:data.msg,
							timeout:2000,
							showType:'slide'
						});
						$("#role_list_datagrid").datagrid('reload');
					}
				});
			}
		});
	}
</script>
</body>
</html>